*********************************************************************
*** Political costs of trade war tariffs 
*** Edward D. Mansfield & Omer Solodoch 
*** Replication code for analysis of the CBS poll  
*** Note: replicators must install the following packages from the SSC Archive:
*** ssc install ebalance
*** ssc install outtable
*** ssc install coefplot
*** ssc install esttab
*********************************************************************

clear all
set mem 600m
set matsize 800	
version 17
set more off
set logtype text
set scheme s1mono
*** Set working directory
capture cd "XXXX"
*** Load dataset
use "MSJOP_CBS.dta", clear


areg TRUMPAPP1 ///
post_escalation i.education i.PRTYLEAN  SEX i.AGEA i.race i.urban [aw=WEIGHT], absorb(state)
gen sample=e(sample)


*************************************************************************************
** Table 1
*************************************************************************************
*************************************************************************************
estimates clear
foreach var in TRUMPAPP1 TrumpAppStl1 StlTrfTrdWar2 TrdWrYou2 TRUMPIMM1 TrumpAppNK1 {
	eststo: areg `var' ///
post_escalation i.education i.INCN3 i.PRTYLEAN  SEX i.AGEA i.race i.urban [aw=WEIGHT], absorb(state) robust
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
}

 esttab est1 est2 est3 est4 est5 est6, keep(post_escalation) ///
order(post_escalation)  ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 s(controls sfixedef N r2, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "R-squared"))
*************************************************************************************
*************************************************************************************

*************************************************************************************
*** appendix
*************************************************************************************

*************************************
** Table A-1: balance test
*************************************
format sex2 education1 education2 collegegrad income PRTYLEAN1 PRTYLEAN2 PRTYLEAN3  race1 race2 race3 race4 urban_1 urban_2 urban_3 %9.2fc
format  age  %9.1fc
bysort post_escalation: sum sex2 age education1 education2 collegegrad income PRTYLEAN1 PRTYLEAN2 PRTYLEAN3  race1 race2 race3 race4 urban_1 urban_2 urban_3 if sample ==1&age<., sep(100) format
**************************************

*************************************
** Figure A-2: balance test
*************************************
 logit post_escalation  /// 
  education2 education3 education4 income2 income3 income4 PRTYLEAN2 PRTYLEAN3 sex2 ///
   AGEA2 AGEA3 AGEA4 AGEA5 race2 race3 race4 urban_2 urban_3 
	coefplot, drop(_cons) xline(0, lp(dash) lc(gs8)) label ///
	xline(-1(0.2)1, lwidth(thin) lcolor(gs8%30))  xlabel(-1(0.2)1) xti(Effect of characteristic on assignment to treatment) ///
 mcolor(maroon) msize(large) ciopts(color(maroon) lwidth(0.7)) 

**************************************************************************
** Tables A-2 & A-3 
**************************************************************************
  estimates clear
eststo: areg TRUMPAPP1 post_escalation i.education i.INCN3 i.PRTYLEAN  SEX i.AGEA i.race i.urban [aw=WEIGHT] if race3==0, absorb(state)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local model "No Hispanic Rs", replace

********************************************************
** Table A-3: balance before and after entropy balancing
********************************************************
ebalance post_escalation  /// 
  education2 education3 education4 income2 income3 income4 PRTYLEAN2 PRTYLEAN3 sex2 ///
  AGEA2 AGEA3 AGEA4 race2 race3 race4 urban_2 urban_3
  ***with labels:
matrix A = e(preBal)
matrix B = e(postBal)
 esttab mat(A, fmt(%9.3fc)), label compress 
 esttab mat(B, fmt(%9.3fc)), label compress  

eststo: areg TRUMPAPP1 post_escalation education2 education3 education4 income2 income3 income4 PRTYLEAN2 PRTYLEAN3 sex2 ///
  AGEA2 AGEA3 AGEA4 race2 race3 race4 urban_2 urban_3 [aweight=_webal], absorb(state)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local model "Entropy balancing", replace

*********************************************************
** Table A-2: excluding Hispanic Rs and entropy balancing  
*********************************************************
 esttab est1 est2, keep(post_escalation) ///
order(post_escalation) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01)  compress nonotes nogaps  ///
 s(controls sfixedef model N r2, fmt(0 0 0 0 3) label("Covariates" "State FE" "Test" "Observations" "Pseudo R-squared"))


*********************************************************
** Table A-7: treatment effect by cutoff selection
*********************************************************
label var post_escalation15 "Post-escalation (June 15)"
label var post_escalation "Post-escalation (June 16)"

estimates clear
** full sample
eststo: areg TRUMPAPP1 ///
post_escalation15 i.education i.INCN3 i.PRTYLEAN  SEX i.AGEA i.race i.urban [aw=WEIGHT], absorb(state) 

estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local june15 "treated", replace

eststo: areg TRUMPAPP1 ///
post_escalation i.education i.INCN3 i.PRTYLEAN  SEX i.AGEA i.race i.urban [aw=WEIGHT] if date!=2, absorb(state) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local june15 "missing", replace

eststo: areg TRUMPAPP1 ///
post_escalation i.education i.INCN3 i.PRTYLEAN  SEX i.AGEA i.race i.urban [aw=WEIGHT], absorb(state) 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local june15 "control", replace

 esttab est1 est2 est3, keep(post_escalation15 post_escalation) ///
order(post_escalation15 post_escalation) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01)  compress nonotes nogaps  ///
 s(controls sfixedef june15 N r2, fmt(0 0 0 0 3) label("Covariates" "State FE" "June 15 coded as:" "Observations" "R-squared"))


**************************************************************************
** Table A-9: robustness, alternative coding for DK responses 
**************************************************************************
estimates clear
eststo: areg TRUMPAPP1 post_escalation i.education i.PRTYLEAN  SEX i.AGEA i.race [aw=WEIGHT], absorb(state)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local dkcoded "0", replace

eststo: areg TrumpApproval3 post_escalation i.education i.PRTYLEAN  SEX i.AGEA i.race [aw=WEIGHT], absorb(state)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local dkcoded "midpoint (2)", replace

eststo: areg TRUMPAPP1 post_escalation i.education i.PRTYLEAN  SEX i.AGEA i.race [aw=WEIGHT] if TrumpApproval3!=2, absorb(state)
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
estadd local dkcoded "missing", replace

 esttab est1 est3 est2, keep(post_escalation) ///
order(post_escalation) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps mtitles("Approve (0/1)" "Approve (0/1)" "Approve (1-3)")  ///
 s(controls sfixedef dkcoded N r2, fmt(0 0 0 0 3) label("Covariates" "State FE" "DK coded as" "Observations" "R-squared"))



**************************************************************************
** Table A-11: robustness test, logistic regression models
**************************************************************************
label var post_escalation "Post-escalation"
estimates clear
foreach var in TRUMPAPP1 TrumpAppStl1 StlTrfTrdWar2 TrdWrYou2 TRUMPIMM1 TrumpAppNK1 {
	eststo:  logit `var' ///
post_escalation i.education i.INCN3 i.PRTYLEAN  SEX i.AGEA i.race i.urban i.state 
estadd local controls "\checkmark", replace
estadd local sfixedef "\checkmark", replace
}
 esttab est1 est2 est3 est4 est5 est6, keep(post_escalation) ///
order(post_escalation) ///
 se(3) b(3) replace star(+ 0.10 * 0.05 ** 0.01) label  nonotes nogaps  ///
 s(controls sfixedef N r2_p, fmt(0 0 0 3) label("Covariates" "State FE" "Observations" "Pseudo R-squared"))

 
******************************************************************************* 
******************************************************************************* 
*******************************************************************************